package cn.kgm.makeGod.action;

import cn.kgm.makeGod.Character;
import cn.kgm.makeGod.Relationship;
import cn.kgm.makeGod.RelationshipType;
import cn.kgm.makeGod.condition.EventResult;
import cn.kgm.makeGod.condition.WorldState;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-9-11 11:42
 * @Description: cn.kgm.makeGod.action.ChangeRelationshipAction
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ChangeRelationshipAction implements Action {
    private int valueChange;

    @Override
    public void execute(Character actor, Character target, WorldState world, EventResult result) {
        Relationship rel = actor.getRelationshipTo(target.getId());
        if (rel == null) {
            // 创建新关系
            RelationshipType type = valueChange > 0 ? RelationshipType.FRIEND : RelationshipType.STRANGER;
            rel = new Relationship(actor.getId(), target.getId(), type, valueChange);
            actor.addRelationship(rel);
        } else {
            // 更新现有关系
            int newValue = Math.max(-100, Math.min(100, rel.getValue() + valueChange));
            rel.setValue(newValue);

            // 根据值更新关系类型
            if (newValue >= 80) rel.setType(RelationshipType.LOVER);
            else if (newValue >= 50) rel.setType(RelationshipType.FRIEND);
            else if (newValue <= -50) rel.setType(RelationshipType.SWORN_ENEMY);
            else rel.setType(RelationshipType.STRANGER);
        }

        result.addLog(actor.getName() + "对" + target.getName() + "的关系值变化: " +
                (valueChange > 0 ? "+" : "") + valueChange + ", 当前值: " + rel.getValue());
    }
}
